package com.zynn.service.module.canal.service.impl;

import com.zynn.common.core.utils.TypeConvertUtil;
import com.zynn.feign.module.es.SyncEventFeignService;
import com.zynn.message.queue.constant.MqQueueNameConstant;
import com.zynn.message.queue.service.ScheduleMessagePostProcessor;
import com.zynn.message.queue.service.SenderService;
import com.zynn.service.module.canal.service.CommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Objects;

/**
 *@ClassName CommentsServiceImpl
 *@Description TODO
 *@Author 刘猛
 *@Date 2018/10/9 16:21
 **/
@Service
@Slf4j
public class CommentsServiceImpl implements CommentsService {

    @Autowired
    SyncEventFeignService syncEventFeignService;

    @Autowired
    private SenderService senderService;

    @Override
    public void handleInsert(Map<String, Object> columnsMap) {
        senderService.send(MqQueueNameConstant.FIND_FRIEND_COMMENTS, columnsMap,new ScheduleMessagePostProcessor(1000L,0L,null,null));
    }

    @JmsListener(destination = MqQueueNameConstant.FIND_FRIEND_COMMENTS)
    public void findDegOneFriend(Map<String, Object> columnsMap) {
        log.info("FIND_FRIEND_COMMENTS:{}", columnsMap);
        /**
         * 评论者id
         */
        Long cuserid = TypeConvertUtil.objectToLong(columnsMap.get("cuserid"));
        if(Objects.nonNull(cuserid)){
            syncEventFeignService.initProcuctFriend(cuserid);
        }

        /**
         * 被评论者id
         */
        Long ceduserid = TypeConvertUtil.objectToLong(columnsMap.get("ceduserid"));
        if(Objects.nonNull(ceduserid)){
            syncEventFeignService.initProcuctFriend(ceduserid);
        }
    }
}
